//
//  THJXSQGDetailVC.m
//  THJXHW
//
//  Created by 河南德艺 on 2018/6/12.
//  Copyright © 2018年 河南德艺. All rights reserved.
//

#import "THJXSQGDetailVC.h"
#import "THJSubmitOrderVC.h"
#import "THJTradeContractVC.h"
#import "THJTradeContractVC2.h"

@interface THJXSQGDetailVC ()
{
    NSDictionary * itemInfo;
    BOOL status;
}
//@property(nonatomic,strong)NSDictionary * itemInfo;
@end

@implementation THJXSQGDetailVC
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = YES;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = SingleColor(whiteColor);
    [self setGoBackBtn];
    [self getItemDetail];
}
- (void)viewWillLayoutSubviews {
    [super viewWillLayoutSubviews];
    self.view.frame = CGRectMake(0, 0, ScreenWidth, ScreenHeight); //所需高度
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)getItemDetail{
    __weak typeof(self) weakself = self;
    NSString * url = [NSString stringWithFormat:@"http://p.thjb.net/thjblink/appdata.php?action=mall_info&itemid=%@",self.itemid];
    [THJNetWork postDataFromUrl:url parameters:@{@"itemid":self.itemid} Token:nil callback:^(NSDictionary* receiveData, NSError *error) {
        if([receiveData[@"status"] isEqual:@"success"]){
            status = YES;
           itemInfo = receiveData[@"data"][@"list"];
            [weakself.imgV sd_setImageWithURL:[NSURL URLWithString:itemInfo[@"thumb"]] placeholderImage:[UIImage imageNamed:@"占位图"]];
            weakself.titleLab.text = itemInfo[@"title"];
            weakself.priceLab.text = [NSString stringWithFormat:@"¥%@/吨",itemInfo[@"price"]];
            weakself.companyLab.text = itemInfo[@"company"];
            weakself.countLab.text = itemInfo[@"amount"];
            weakself.ggLab.text = [THJTools guigeTypeChangeToStrWithType:itemInfo[@"gg"]];
            weakself.dateLab.text = itemInfo[@"adddate"];
            weakself.chandiLab.text = itemInfo[@"jhd"];
        }else{
            status = NO;
            [weakself HUDShowMsg:@"获取信息失败" AfterDelayDimiss:2];
        }
        
    }];
}
- (IBAction)dinggou:(id)sender {
    
//    [self.navigationController pushViewController:[THJTradeContractVC2 new] animated:YES];
    
    if(status){
        THJSubmitOrderVC * vc = [THJSubmitOrderVC new];
        vc.amount = itemInfo[@"amount"];
        vc.pTitle = itemInfo[@"title"];
        vc.img = self.imgV.image;
        vc.price = itemInfo[@"price"];
        vc.itemid = itemInfo[@"itemid"];
        [self.navigationController pushViewController:vc animated:YES];
    }
    
}

@end
